<?php

function showHeader($body = array(), $headers = '') {
	global	$config;
	global	$full_header;
	global	$admin_header;
	global	$phpEx;

	if ($admin_header) {
		$header_tpl	= 'admin/admin_header.tpl';
	} else {
		$header_tpl	= 'overall_header.tpl';
	}

	// 
	// Load template header
	//
	$template = new Template($config['TPL_DIR']);
	$template->set_filenames(array('header' => $header_tpl));
	
	$body_class	= 'class=main ';
	
	if ($body['class']) {
		$body_class	= "class={$body['class']} ";
	}
	
	if ($body['id']) {
		$body_id	= "id={$body['id']} ";
	}
	
	if ($body['bgcolor']) {
		if (substr($body['bgcolor'], 0, 1) == '#') {
			$body_bgcolor	= "bgcolor={$body['bgcolor']} ";
		} else {
			$body_bgcolor	= "bgcolor=#{$body['bgcolor']} ";
		}
	}
	
	if ($body['text']) {
		$body_text	= "\n" . $body['text'];
	}

	if ($body['onload']) {
		$body_onload	= " onLoad='" . $body['onload'] . "'";
	}

	$template->assign_vars(array(
		'FORUM_NAME'	=> $config['FORUM_NAME'],
		'CSS'		=> $config['TPL_WWW'] . $config['TEMPLATE'] . ".css",
		'CLASS'		=> $body_class,
		'ID'		=> $body_id,
		'BGCOLOR'	=> $body_bgcolor,
		'TEXT'		=> $body_text,
		'ONLOAD'	=> $body_onload
	));
	
	if (is_array($headers)) {
		foreach ($headers as $thisHeader) {
			$template->assign_block_vars('switch_headers', $thisHeader);
		}
	}
	
	$adjust = explode("/", $_SERVER['PHP_SELF']);
	$page	= $adjust[count($adjust)-1];

	if ($full_header) {
		$template->assign_block_vars('switch_fullheader', array());

		$links['index']		= array('NAME'	=> "Home",
						'URL'	=> "index.$phpEx");

		$links['transcripts']	= array('NAME'	=> "Transcripts",
						'URL'	=> "transcripts.$phpEx");

		$links['whoson']	= array('NAME'	=> "Who's On",
						'URL'	=> "whoson.$phpEx");

		$links['help']		= array('NAME'	=> "Help Guide",
						'URL'	=> "help.$phpEx");

		foreach ($links as $link) {
			$template->assign_block_vars('switch_fullheader.header_link', $link);
			if ($link['URL'] != $page) {
				$template->assign_block_vars('switch_fullheader.header_link.switch_link', array());
			}
		}
		$tplHead	= "switch_fullheader.";
	}

	if ($admin_header) {
		if ($_SERVER['QUERY_STRING']) {
			$page .= "?" . $_SERVER['QUERY_STRING'];
		}

		$nav	= array('General'	=> array(
					'Home'		=> "../index.$phpEx",
					'Who\'s On'	=> "../whoson.$phpEx"
				),
				'Manage'	=> array(
					'Ban Control'	=> "index.$phpEx?op=ban_control",
					'Rooms'		=> "index.$phpEx?op=manage_rooms",
					'Room Groups'	=> "index.$phpEx?op=manage_groups"
				)
			);
		$tplHead	= "";
	}

	if ($nav) {
		foreach ($nav as $hname => $hlinks) {
			$template->assign_block_vars($tplHead . 'header_group', array('NAME' => $hname));
			foreach ($hlinks as $linkName => $linkURL) {
				$template->assign_block_vars($tplHead . 'header_group.header_link', array('NAME' => $linkName));
				if ($linkURL != $page) {
					$template->assign_block_vars($tplHead . 'header_group.header_link.switch_link', array('URL' => $linkURL));
				}
			}
		}
	}
	$template->pparse('header');
	define('HEADER_LOADED', 1);
}
?>
